package com.example.content.fragment.me.userproduct

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.content.*
import com.example.content.adapter.recycle.BindListener
import com.example.content.adapter.recycle.RecyclerAdapter
import com.example.content.adapter.recycle.entity.ItemEntity
import com.example.content.databinding.RecyclerviewLayoutBinding
import com.example.content.fragment.BaseMvvmFragment
import com.example.content.manager.GlobalMgr
import com.example.content.repository.ApiService
import com.example.content.repository.bean.ProductCollectInfo
import com.example.content.repository.bean.ProductInfo
import com.example.content.viewmodule.me.MyPageCommonViewModel
import com.example.core.utils.DensityUtils

/**
 * A simple [Fragment] subclass.
 * Use the [BaseProductFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
abstract class BaseProductFragment<T>(private val pageType: Int) : BaseMvvmFragment<RecyclerviewLayoutBinding, MyPageCommonViewModel>() {

    open lateinit var adapter:RecyclerAdapter<T>

    override fun initView() {
        dataBinding.refresh.setEnableLoadMore(false)
        dataBinding.refresh.setOnRefreshListener {
            queryData()
        }

        adapter = getAdapterFun()
        adapter.addItemView(R.layout.me_product_list_item_layout)
        val layoutManager = GridLayoutManager(context, 2)
        dataBinding.recyclerView.adapter = adapter
        dataBinding.recyclerView.layoutManager = layoutManager
        dataBinding.recyclerView.setPadding(DensityUtils.dp2px(10f), 0, DensityUtils.dp2px(10f), 0)
    }

    abstract fun getAdapterFun(): RecyclerAdapter<T>

    override fun queryData() {
//        viewModel.queryUserPage(pageType)
    }

    override fun initListener() {
        super.initListener()
        GlobalMgr.productDel.observe(this, {
            if (it) {
                queryData()
            }
        })
        viewModel.responseResult.observe(this, {
            dataBinding.refresh.finishRefresh()
        })
    }

    override fun getLayoutId() = R.layout.recyclerview_layout

    override fun getViewModuleClass(): Class<MyPageCommonViewModel> {
        return MyPageCommonViewModel::class.java
    }
}